# !/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time : 3/19/21 6:04 PM
# @Author : minvan
# @Email : jiangming8937@icloud.com
# @File : SuperChauffeuring.py
# @Software: PyCharm


import sys
import json
import requests
import logging


class SuperChauffeuring(object):
    def __init__(self):
        self.Url = 'https://a.heyuapp.cn'
        self.Cookie = "spcar-session=.eJwljksOwyAMBe9Ctl0YY4PJZSKwocmiUpWPuqh691J1Pe-N5u2WvrdjdfO5X-3mls3c7LhIrU1QW00RQbMaBIAawQwNYxOoSKClewhNlCQzRjZfgTMD2DhEIl-VzXoKhMoUhJAzQeKMxQt2zjn6ISxWMo-ZYkgBaujBjZDraPu_xnsRmqayHE8t-4-9tnNdHuW-6cDu8wWV2zfA.YDdoAQ.AOLlzXt3QVvJvXw_s9qciLovU_U; shunt-key=02ccbbcebe2779c9c9daf6850b73c276"

        # print(CookieValue)

    @staticmethod
    def DiyJson(**kwargs):
        '''
        :param kwargs:
        :return: jsons
        '''
        jsons = {}
        if kwargs:
            jsons.update(kwargs)
            logging.info(sys._getframe(0).f_code.co_name+json.dumps(jsons))
            return json.dumps(jsons, ensure_ascii=False)
        else:
            pass

    @staticmethod
    def DiyRaw(**kwargs):
        print(kwargs)
        s = lambda x, y: x + y, range(100)
        print(type(s))

    def test(self):
        Cookie = {'Cookie':self.Cookie}
        Url = self.Url+"/spcar/webapi/weapp/user/miniapp/settings"
        Resp = requests.get(url=Url,params=None,headers=Cookie)
        print(Resp.content.decode())

    @staticmethod
    def Color(RGB):
        if RGB[0]=="#":
            str1 = RGB[1:3]
            str2 = RGB[3:5]
            str3 = RGB[5:7]
            num1 = int('0x' + str1, 16)
            num2 = int('0x' + str2, 16)
            num3 = int('0x' + str3, 16)
            print("rgb(%s, %s, %s)" % (str(num1), str(num2), str(num3)))
            rgb = (str(num1), str(num2), str(num3))
        else:
            list = RGB.split(',')
            str1 = list[0][4:]
            str2 = list[1][1:]
            str3 = list[2][1:-1]
            # hex返回的字母A~F均为小写字母a~f，根据样例输出，用upper函数把字母全部转为大写
            hex1 = hex(int(str1))[2:].upper()
            hex2 = hex(int(str2))[2:].upper()
            hex3 = hex(int(str3))[2:].upper()
            # 十进制转16进制时会出现缺省零的情况，用rjust函数可在字符串左侧填充0
            # 同理 ljust函数可在字符串的右侧填充0
            hex1 = hex1.rjust(2, '0')
            hex2 = hex2.rjust(2, '0')
            hex3 = hex3.rjust(2, '0')
            outputstr = "#"
            rgb = outputstr + hex1 + hex2 + hex3
        return rgb



    def OrderInfoCurrent(self):
        Url = self.Url + "/spcar/webapi/weapp/order/info/current"
        Headers = {"Cookie":self.Cookie}
        print(Headers)
        resp = requests.get(url=Url,params=None,headers=Headers)
        print(resp.content.decode())


class DestroyOrder(SuperChauffeuring):
    def __init__(self):
        self.OrderType = ["service"]
        self.Status = ["DRIVING","",]

# if __name__ == '__main__':
#     # pass
#     SassWxMiniApp().OrderInfoCurrent()
